/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GajiGUI.java
 *
 * Created on 16 Jul 12, 13:58:14
 */
package gui;

import dao.GajiDAO;
import dao.GolonganDAO;
import dao.KaryawanDAO;
import entity.tbGaji;
import entity.tbGolongan;
import entity.tbKaryawan;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Dhurand
 */
public class GajiGUI extends javax.swing.JFrame {

    //Persistence
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("SI_GajiPU");
    EntityManager em = emf.createEntityManager();
    //DAO
    KaryawanDAO kDAO = new KaryawanDAO(em);
    GolonganDAO gDAO = new GolonganDAO(em);
    GajiDAO gajiDAO = new GajiDAO(em);

    public void initAwal() {
        nama_txt.setEditable(false);
        golongan_txt.setEditable(false);
        gajipokok_txt.setEditable(false);
        pajak_txt.setEditable(false);
        tunjangan_btn.setSelected(false);
        tunjangan_panel.setVisible(false);
    }

    public void resetAll() {
        nama_txt.setText("");
        golongan_txt.setText("");
        gajipokok_txt.setText("");
        pajak_txt.setText("");

        tunjangan_panel.setVisible(false);
        tunjangan_btn.setSelected(false);
        tunjangan1_chk.setSelected(false);
        tunjangan2_chk.setSelected(false);
        tunjangan1_txt.setText("");
        tunjangan1_txt.setEnabled(false);
        tunjangan2_txt.setText("");
        tunjangan2_txt.setEnabled(false);

        bulan_cmb.setSelectedIndex(0);

        this.bindingGaji();
        this.bindingKaryawan();
    }

    public void bindingKaryawan() {

        try {
            String[] title = {"ID", "Nama", "Golongan"};
            Object[][] data = new Object[kDAO.getAll().size()][3];

            int i = 0;
            while (i < kDAO.getAll().size()) {
                data[i][0] = kDAO.getAll().get(i).getId();
                data[i][1] = kDAO.getAll().get(i).getNama();
                data[i][2] = kDAO.getAll().get(i).getGolongan();
                i++;
            }

            DefaultTableModel model = new DefaultTableModel(data, title);
            tabelkaryawan.setModel(model);
            this.jScrollPane1.setViewportView(tabelkaryawan);
        } catch (Exception e) {
            e.getMessage();
        }
    }

    public void bindingGaji() {
        try {
            String[] title = {"ID", "Nama", "Golongan", "Gaji Pokok", "Tunjangan 1", "Tunjangan 2", "Pajak", "Gaji Bersih", "Bulan"};
            Object[][] data = new Object[gajiDAO.getAll().size()][9];

            int i = 0;
            while (i < gajiDAO.getAll().size()) {
                data[i][0] = gajiDAO.getAll().get(i).getId();
                data[i][1] = gajiDAO.getAll().get(i).getNama();
                data[i][2] = gajiDAO.getAll().get(i).getGolongan();
                data[i][3] = gajiDAO.getAll().get(i).getGajiPokok();
                data[i][4] = gajiDAO.getAll().get(i).getTunjangan1();
                data[i][5] = gajiDAO.getAll().get(i).getTunjangan2();
                data[i][6] = gajiDAO.getAll().get(i).getPajak();
                data[i][7] = gajiDAO.getAll().get(i).getGajiBersih();
                data[i][8] = gajiDAO.getAll().get(i).getBulan();
                i++;
            }

            DefaultTableModel model = new DefaultTableModel(data, title);
            tabelgaji.setModel(model);
            //tabelgaji.setEnabled(false);
            //tabelgaji.setDragEnabled(false);
            this.jScrollPane2.setViewportView(tabelgaji);
        } catch (Exception e) {
            e.getMessage();
        }
    }

    /** Creates new form GajiGUI */
    public GajiGUI() {
        initComponents();

        initAwal();
        setLocationRelativeTo(null);
        this.setTitle("Form Input Gaji");

        //System.out.println(kDAO.getAll().size());
        this.bindingKaryawan();
        this.bindingGaji();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        nama_txt = new javax.swing.JTextField();
        golongan_txt = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        gajipokok_txt = new javax.swing.JTextField();
        pajak_txt = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        tunjangan_btn = new javax.swing.JToggleButton();
        tunjangan_panel = new javax.swing.JPanel();
        tunjangan1_txt = new javax.swing.JTextField();
        tunjangan2_txt = new javax.swing.JTextField();
        tunjangan1_chk = new javax.swing.JCheckBox();
        tunjangan2_chk = new javax.swing.JCheckBox();
        jLabel9 = new javax.swing.JLabel();
        bulan_cmb = new javax.swing.JComboBox();
        insert_btn = new javax.swing.JButton();
        reset_btn = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tabelkaryawan = new javax.swing.JTable();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tabelgaji = new javax.swing.JTable();
        inputGaji_btn = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        jPanel1.setBackground(new java.awt.Color(204, 255, 255));

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel1.setText("Input Gaji");

        jLabel2.setText("Nama");

        jLabel3.setText("Golongan");

        jLabel4.setText("Gaji Pokok");

        jLabel5.setText("Pajak");

        jLabel6.setText("%");

        tunjangan_btn.setText("Tunjangan");
        tunjangan_btn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tunjangan_btnActionPerformed(evt);
            }
        });

        tunjangan_panel.setBackground(new java.awt.Color(204, 204, 204));

        tunjangan1_chk.setText("Tunjangan 1");
        tunjangan1_chk.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tunjangan1_chkActionPerformed(evt);
            }
        });

        tunjangan2_chk.setText("Tunjangan 2");
        tunjangan2_chk.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tunjangan2_chkActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout tunjangan_panelLayout = new javax.swing.GroupLayout(tunjangan_panel);
        tunjangan_panel.setLayout(tunjangan_panelLayout);
        tunjangan_panelLayout.setHorizontalGroup(
            tunjangan_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tunjangan_panelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(tunjangan_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tunjangan1_chk)
                    .addComponent(tunjangan2_chk))
                .addGap(18, 18, 18)
                .addGroup(tunjangan_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(tunjangan2_txt, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(tunjangan1_txt, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 156, Short.MAX_VALUE))
                .addContainerGap(35, Short.MAX_VALUE))
        );
        tunjangan_panelLayout.setVerticalGroup(
            tunjangan_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tunjangan_panelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(tunjangan_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tunjangan1_chk)
                    .addComponent(tunjangan1_txt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(tunjangan_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tunjangan2_txt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tunjangan2_chk))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel9.setText("Bulan");

        bulan_cmb.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember" }));

        insert_btn.setText("Insert");
        insert_btn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                insert_btnActionPerformed(evt);
            }
        });

        reset_btn.setText("Reset");
        reset_btn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                reset_btnActionPerformed(evt);
            }
        });

        tabelkaryawan.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null}
            },
            new String [] {
                "ID", "Nama", "Golongan"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tabelkaryawan.setColumnSelectionAllowed(true);
        tabelkaryawan.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(tabelkaryawan);
        tabelkaryawan.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        tabelkaryawan.getColumnModel().getColumn(0).setResizable(false);
        tabelkaryawan.getColumnModel().getColumn(1).setResizable(false);
        tabelkaryawan.getColumnModel().getColumn(2).setResizable(false);

        jLabel7.setText("Tabel Karyawan");

        jLabel8.setText("Tabel Gaji");

        tabelgaji.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null, null}
            },
            new String [] {
                "ID", "Nama", "Golongan", "Gaji Pokok", "Tunjangan 1", "Tunjangan 2", "Pajak", "Gaji Bersih", "Bulan"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tabelgaji.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        tabelgaji.setEnabled(false);
        jScrollPane2.setViewportView(tabelgaji);
        tabelgaji.getColumnModel().getColumn(0).setResizable(false);
        tabelgaji.getColumnModel().getColumn(1).setResizable(false);
        tabelgaji.getColumnModel().getColumn(2).setResizable(false);
        tabelgaji.getColumnModel().getColumn(3).setResizable(false);
        tabelgaji.getColumnModel().getColumn(4).setResizable(false);
        tabelgaji.getColumnModel().getColumn(5).setResizable(false);
        tabelgaji.getColumnModel().getColumn(6).setResizable(false);
        tabelgaji.getColumnModel().getColumn(7).setResizable(false);
        tabelgaji.getColumnModel().getColumn(8).setResizable(false);

        inputGaji_btn.setText("Input Gaji");
        inputGaji_btn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                inputGaji_btnActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(20, Short.MAX_VALUE)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8))
                .addContainerGap(20, Short.MAX_VALUE))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(inputGaji_btn)
                .addContainerGap(385, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(7, 7, 7)
                .addComponent(inputGaji_btn)
                .addGap(18, 18, 18)
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 115, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tunjangan_panel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5))
                        .addGap(37, 37, 37)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(golongan_txt, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(pajak_txt, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel6))
                            .addComponent(tunjangan_btn)
                            .addComponent(nama_txt, javax.swing.GroupLayout.DEFAULT_SIZE, 222, Short.MAX_VALUE)
                            .addComponent(gajipokok_txt, javax.swing.GroupLayout.PREFERRED_SIZE, 184, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(insert_btn, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel9)
                                .addGap(62, 62, 62)
                                .addComponent(bulan_cmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(reset_btn, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(47, 47, 47)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(nama_txt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(golongan_txt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(gajipokok_txt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(pajak_txt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6))
                        .addGap(18, 18, 18)
                        .addComponent(tunjangan_btn)
                        .addGap(18, 18, 18)
                        .addComponent(tunjangan_panel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel9)
                            .addComponent(bulan_cmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(insert_btn)
                            .addComponent(reset_btn))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void reset_btnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reset_btnActionPerformed
        // TODO add your handling code here:
        resetAll();
    }//GEN-LAST:event_reset_btnActionPerformed

    private void tunjangan_btnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tunjangan_btnActionPerformed
        // TODO add your handling code here:
        if (tunjangan_btn.isSelected()) {
            tunjangan_panel.setVisible(true);
            tunjangan1_chk.setSelected(false);
            tunjangan2_chk.setSelected(false);
            tunjangan1_txt.setText("");
            tunjangan1_txt.setEnabled(false);
            tunjangan2_txt.setText("");
            tunjangan2_txt.setEnabled(false);
        } else {
            tunjangan_panel.setVisible(false);
        }
    }//GEN-LAST:event_tunjangan_btnActionPerformed

    private void tunjangan1_chkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tunjangan1_chkActionPerformed
        // TODO add your handling code here:
        if (tunjangan1_chk.isSelected()) {
            tunjangan1_txt.setEnabled(true);
        } else {
            tunjangan1_txt.setEnabled(false);
            tunjangan1_txt.setText("");
        }
    }//GEN-LAST:event_tunjangan1_chkActionPerformed

    private void tunjangan2_chkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tunjangan2_chkActionPerformed
        // TODO add your handling code here:
        if (tunjangan2_chk.isSelected()) {
            tunjangan2_txt.setEnabled(true);
        } else {
            tunjangan2_txt.setEnabled(false);
            tunjangan2_txt.setText("");
        }
    }//GEN-LAST:event_tunjangan2_chkActionPerformed

    private void inputGaji_btnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_inputGaji_btnActionPerformed
        // TODO add your handling code here:

        try {
            tbKaryawan k = kDAO.getAll().get(tabelkaryawan.getSelectedRow());
            nama_txt.setText(k.getNama());
            golongan_txt.setText(k.getGolongan());

            List<tbGolongan> g = gDAO.searchByGolongan(k.getGolongan());
            gajipokok_txt.setText(String.valueOf(g.get(0).getGajiPokok()));
            pajak_txt.setText(String.valueOf(g.get(0).getPajak()));
            //System.out.println(g.get(0).getGajiPokok());
            //System.out.println(g.get(0).getPajak());
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Pilih Karyawan Terlebih Dahulu");
        }



    }//GEN-LAST:event_inputGaji_btnActionPerformed

    private void insert_btnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_insert_btnActionPerformed
        // TODO add your handling code here:
        String nama;
        String golongan;
        double gajiPokok;
        double pajak;
        double tunjangan1 = 0;
        double tunjangan2 = 0;
        String bulan;
        double gajiBersih;

        try {

            if (nama_txt.getText().equals("") || golongan_txt.getText().equals("")
                    || gajipokok_txt.getText().equals("") || pajak_txt.getText().equals("")) {
                JOptionPane.showMessageDialog(this, "Data Kosong");
            } else {

                if (tunjangan1_txt.getText().equals("")) {
                    tunjangan1 = 0;
                }

                if (tunjangan2_txt.getText().equals("")) {
                    tunjangan2 = 0;
                }
                
                else{
                    tunjangan1 = Double.parseDouble(tunjangan1_txt.getText());
                    tunjangan2 = Double.parseDouble(tunjangan2_txt.getText());
                }

                nama = nama_txt.getText();
                golongan = golongan_txt.getText();
                gajiPokok = Double.parseDouble(gajipokok_txt.getText());
                pajak = Double.parseDouble(pajak_txt.getText());
                
                bulan = bulan_cmb.getSelectedItem().toString();

                gajiBersih = (gajiPokok + tunjangan1 + tunjangan2) - ((pajak / 100) * gajiPokok);
                
                tbGaji gaji = new tbGaji();
                gaji.setNama(nama);
                gaji.setGolongan(golongan);
                gaji.setGajiPokok(gajiPokok);
                gaji.setPajak(pajak);
                gaji.setTunjangan1(tunjangan1);
                gaji.setTunjangan2(tunjangan2);
                gaji.setBulan(bulan);
                gaji.setGajiBersih(gajiBersih);
                
                gajiDAO.insert(gaji);
                
            }

            this.bindingGaji();
            this.bindingKaryawan();


        } catch (Exception e) {
            e.printStackTrace();
        }

    }//GEN-LAST:event_insert_btnActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new GajiGUI().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox bulan_cmb;
    private javax.swing.JTextField gajipokok_txt;
    private javax.swing.JTextField golongan_txt;
    private javax.swing.JButton inputGaji_btn;
    private javax.swing.JButton insert_btn;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextField nama_txt;
    private javax.swing.JTextField pajak_txt;
    private javax.swing.JButton reset_btn;
    private javax.swing.JTable tabelgaji;
    private javax.swing.JTable tabelkaryawan;
    private javax.swing.JCheckBox tunjangan1_chk;
    private javax.swing.JTextField tunjangan1_txt;
    private javax.swing.JCheckBox tunjangan2_chk;
    private javax.swing.JTextField tunjangan2_txt;
    private javax.swing.JToggleButton tunjangan_btn;
    private javax.swing.JPanel tunjangan_panel;
    // End of variables declaration//GEN-END:variables
}
